-
Notifications
You must be signed in to change notification settings - Fork 631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC WIP] define modular arithmetic in theories/Numbers/Zmod.v #17043
Conversation
fa6f9b4
to
a977649
Compare
Thanks for creating this PR! I think the definitions provided by this PR fill an important hole in the Coq standard library. I needed a library for fixed sized integers in the context of the Islaris project and since there is currently no implementation in the standard library, I had to implement my own library (which now lives in std++). I am not the only one who has this problem, as I know of quite a few (at least 5 I think) implementations of fixed size integers libraries. However, it is not really possible to reuse code outside of the standard library since e.g. libraries like std++ cannot have dependencies except Coq. So I think it would be really great to have these core concepts like fixed-size integers provided by the Coq standard library such that they can be shared and built-upon by the ecosystem. |
2843d99
to
0838fd0
Compare
This is not ready for merge-review, but what is already here is representative of what I am proposing. I would appreciate high-level feedback about scope and strategy. For example, it would be neat if another maintainer of (of stdlib, numbers, or even another word/ZnZ library) took a look at every file, module, or |
Like @MackieLoeffel I also think this fills an important gap in the standard library; projects that want to reason about fixed-size integers, e.g. for proofs about virtually any programming language, currently use a smattering of mostly homegrown implementations. For cryptography proofs, the basic modular arithmetic lemmas and the proof of Fermat's Little Theorem (often used for computing the inverse of a finite field element) are especially useful. I looked through all the code and the setup/design makes sense to me as a heavy user of modular arithmetic in Coq, for whatever that's worth 🙂 I can leave a detailed review if it helps the PR not fall through the cracks, but I'm not a stdlib maintainer. |
m = n -> to_Z a = to_Z b -> existT _ _ a = existT _ _ b. | ||
Proof. destruct 1; auto using f_equal, to_Z_inj. Qed. | ||
|
||
(** Conversions to Fin.t *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(** Conversions to Fin.t *) | |
(** ** Conversions to Fin.t *) |
|
||
(** Conversions to Fin.t *) | ||
|
||
(* Please consider using [to_nat] or [to_N] instead. *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(* Please consider using [to_nat] or [to_N] instead. *) | |
(** Please consider using [to_nat] or [to_N] instead. *) |
e839ab5
to
2afa286
Compare
@coq/number-maintainers Could I get a review on this? Thanks! |
2afa286
to
9aca9cf
Compare
9aca9cf
to
1850345
Compare
Not a review but only a quick look:
Please rebase/squash and ping when you consider it ready for final review/merge Cc @Villetaneuse who may have an opinion too |
Thank you for the feedback. Here are quick responses:
|
Ok, let's keep it as it is. Please just make sure when rebasing to have clear and consistent commits.
Ok
Ok for clarifying Narith_base later.
Some users want to use PArith without having to depend on the whole ZArith and micromega. As already discussed on zulip, the fact that all those dependencies are not very clear, and not enforced in the CI, led to the current mess. We could hope to clarify this, enabling a clean split into meaningful subpackages, and enforcement of their dependencies in the CI. If only due to the way Coq works (
Ok, maybe we should indeed accept that modules are not so convenient as an abstraction facility.
Ok, that was just a question out of curiosity, let's keep things as they are in this PR. And also ok for moving cyclic to bignums in separate PRs (one to bignums for the addition, one here for the deletion). |
I am struggling to make sense of this requirement. Do you actually intend to require that any lemmas about EDIT: As a user, I |
Have you considered also looking at CompCert: |
I did look at it a while ago, I just forgot to list it. IIRC the overall conceptual design is rather similar to how what I am doing here applies mod Is there something specific there that you are interested in? |
Not specifically, we depended on it for hacspec at some point. Vst also
uses it, I believe. Certicoq maybe. So, unifying it would probably be good.
from my phone
…On Thu, Mar 14, 2024, 17:50 Andres Erbsen ***@***.***> wrote:
I did look at it a while ago, I just forgot to list it. IIRC the overall
conceptual design is rather similar to how what I am doing here applies mod
2^m, but the int interface also includes operations that handle carry
flags and sign extension which I am unsure about. I do think it would be
valuable to eventually aim for comparable coverage of properties of already
included bitwise operations, though.
Is there something specific there that you are interested in?
—
Reply to this email directly, view it on GitHub
<#17043 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABTNTQTE6HBLZBS3KKHCXLYYHIMTAVCNFSM6AAAAAATNFNESGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOJXHA4TQNZZGM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
The "needs: rebase" label was set more than 30 days ago. If the PR is not rebased in 30 days, it will be automatically closed. |
This PR was not rebased after 30 days despite the warning, it is now closed. |
In the spirit of consolidating often-reimplemented functionality, here is a self-contained middle-of-the-road definition of modular arithmetic. The intent is for this construction to be usable for number theory (as in Coqprime), finite-field algebra (as in Fiat Cryptography), and modeling machine words (as in Bedrock2, etc). The implementation is written from scratch, based on lessons learned from these projects and observations from others' issue trackers.
I am sharing this now to get general feedback on what to define and how. The overall scope in the current PR is about what I would like to place in the standard library at first, though I expect that I'd be motivated to finish up integration with the other stdlib algebraic hierarchy (
Ring
,Nsatz
,lia
, etc) before merging. The best way to read the code right now is to start fromZmod.Base
, search for**
to find conceptual sections, and jump forward one empty line at the time.